package itheima.com.socketdemo7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",5555);
        OutputStream os = socket.getOutputStream();
        os.write("Hello".getBytes());
//        is.close();  在这里不关流下面代码无法执行，关流会导致整个socket无法使用
        socket.shutdownOutput();//仅仅关闭输出流，并写一个结束标记，对socket没有任何影响

        /*InputStream is = socket.getInputStream();
        int a;
        while ((a=is.read())!=-1){
            System.out.println((char)a);
        }*/

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String ss;
        while ((ss=br.readLine())!=null){
            System.out.println(ss);
        }

        os.close();
        br.close();
        socket.close();

    }
}
